<?php

namespace app\repository\dao\api;

use support\Db;

class ProductDao
{
    public function getList(array &$data): array
    {
        $fields = [
            'id', 'image_url', 'product_alias', 'orgz_id', 'status', 'plu', 'is_archive',
            'current_price', 'weight_type', 'min_spec_unit', 'cid', 'source_code', 'str_spec',
            'producing_place', 'product_grade', 'code', 'tag_id', 'vip_price', 'brand',
            'custom_code', 'restock_price', 'purchase_price', 'pid', 'conversion_factor',
            'closely_barcode_id'
        ];
        $query = Db::table('product_orgz');

        $total = $query->count();
        $list = $query->offset($data['start'])
            ->limit($data['length'])
            ->orderBy('id', 'DESC')
            ->select($fields)
            ->get()->toArray();
        return ['total' => $total, 'list' => $list];
    }
}